package com.byd.android.agreement.message;

import com.byd.android.agreement.BaseMessage;
import com.google.gson.JsonObject;

public class Music extends BaseMessage {
    private int id = 0;  //标识码
    private int duration = 0;//时长
    private String artist = null;//演唱者
    private String musicName = null;//音乐名
    private String data;//文件路径


    public Music(){};
    public Music(int id, int duration, String artist, String musicName, String data) {
        this.id = id;
        this.duration = duration;
        this.artist = artist == null ? "" : artist;
        this.musicName = musicName == null ? "" : musicName;
        this.data = data == null ? "" : data;
    }

    @Override
    public String toString() {
        return "Music{" +
                "id=" + id +
                ", duration=" + duration +
                ", artist='" + artist + '\'' +
                ", musicName='" + musicName + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public String getArtist() {
        return artist;
    }

    public void setArtist(String artist) {
        this.artist = artist == null ? "" : artist;
    }

    public String getMusicName() {
        return musicName;
    }

    public void setMusicName(String musicName) {
        this.musicName = musicName == null ? "" : musicName;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data == null ? "" : data;
    }

    public static Music parseJson(String jstr) {
        Music music = new Music();
        JsonObject jobj = mParser.parse(jstr).getAsJsonObject();
        music.setId(jobj.get("id").getAsInt());
        music.setDuration(jobj.get("duration").getAsInt());
        music.setArtist(jobj.get("artist").getAsString());
        music.setMusicName(jobj.get("musicName").getAsString());
        music.setData(jobj.get("data").getAsString());
        return music;
    }
}
